#pragma once
#include <iostream>
#include <string>
#include <iomanip>
#include <sstream>
#include <vector>
#include <fstream>
#include "Student.h"

using namespace std;

	class StudentRegister 
	{

	private:

		vector<Student> studvect;

	public:

		StudentRegister(void){}

		~StudentRegister(void){}

		void Add(Student student){studvect.push_back(student);}

		string List()
		{
			ostringstream oss;
				
			for(int i =0; i < studvect.size(); i++)
			{
				cout << studvect[i] << endl ;
			}
			return oss.str();
		}

	
		void WriteToFile(string filename)
		{
		 ofstream fout(filename);
	 
			for (auto &student : studvect)
			{
				fout << student << endl;
			}
	
			fout.close();
	
		}

		void ReadfromFile(string filename)
		{
		
			string str,strRow;
			ifstream fin;
			
		
			try
			{
				fin.open(filename);
				studvect.clear();
			
				while(getline(fin,strRow))
				{
					stringstream iss(strRow);

					Student S;

					iss >> S;
					if(S.GetFirstName()!="")
					{
						studvect.push_back(S);
					}
				}
				fin.close();
			}
			 catch (exception e)
			 {
				cerr << "Exception " << filename << endl;
				cerr << e.what() << endl;
			 }
			
			
		
		}

	
	
	};



